package com.focus.xyz.other.cases;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.common.listeners.TC;
import com.focus.xyz.core.common.webdriver.DriverFactory;
import com.focus.xyz.core.utils.ProcessUtil;
import com.focus.xyz.other.pages.pingan.AppTracePage;
import com.focus.xyz.other.pages.pingan.HomePage;
import com.focus.xyz.other.pages.pingan.OrderPage;
import com.focus.xyz.union.action.KeyWordAction;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by chenmeng on 2016/6/29.
 */
public class PinganTest extends TC {
    private WebDriver driver;
    private Action action;

    @Parameters({"nodeUrl","browser"})
    @BeforeMethod(alwaysRun = true)
    public void setUp(String nodeUrl,String browser) throws Exception {
        driver = DriverFactory.getDriver(nodeUrl).getBrowser(browser);
        super.init(driver);
        action = new KeyWordAction(driver);
    }


    @Parameters({"browser"})
    @AfterMethod(alwaysRun = true)
    public void tearDown(String browser) {
        try{
            super.quit();
            driver.quit();
        }catch (Exception e){
            ProcessUtil.closeBrowser(browser);
        }finally {

        }
    }

    @Test
    public void test001() throws Exception{
        HomePage homePage = new HomePage(driver,action);
        homePage.openPage();
        /*登录系统*/
        homePage.login("XYZ-00001","74h6qrWg");
        action.pause(1000l);
        homePage.switchMain();
        /*个人出单*/
        homePage.newOffer("21077","2100700666");
        action.waitForPageLoad();
        action.pause(3000l);
        OrderPage orderPage = new OrderPage(driver,action);

        /*根据车架号 查询续保*/
        /*orderPage.search("苏A-28347");
        ResultPage resultPage = new ResultPage(driver,action);
        resultPage.confirmCarInfo();*/

        /*客户信息检索*/
        orderPage.searchCust("阳丽芬",null,"342622198809067128");

        /*车辆信息检索,苏A-F02P0*/
        orderPage.fillCardInfo("苏A-F02P0","3829492","LVSHCFDBXFE139172","福克斯CAF7163A4","FKD1059CAF/福克斯CAF7163A4轿车/长安福特马自达/三厢 双离合 舒适型 国Ⅳ/106900.0/2012","2016-07-06");

        /*选择保障 险种 险别*/
        Map taxInfo = new HashMap<String,String>();
        taxInfo.put("taxtype","减税");
        taxInfo.put("reducereason","能源减免");
        taxInfo.put("reducetype","比例减免");
        taxInfo.put("reducerate","0.5");
        taxInfo.put("taxno","232221");
        orderPage.selectInsType(new String[]{"商业险","交强险"},taxInfo,new String[]{"机动车第三者责任保险","机动车损失保险"});
        action.pause(2000l);

        /*被保人信息*/
        orderPage.selectInsured("18061273225");
        orderPage.applyQuote();

        action.pause(5000l);
        String qouteResult = orderPage.getQuoteResult().split(":")[1];

        System.out.println(qouteResult);

        /*
        * 根据证单号查询报价
        * */
        homePage.switchDefault();
        homePage.clickTraceMenu();
        homePage.switchMain();
        AppTracePage tracePage = new AppTracePage(driver,action);
        String appFee = tracePage.searchAppFee(qouteResult);

        System.out.println(appFee);
    }

    /*public void login(String userName,String pass) throws Exception{
        HomePage homePage = new HomePage(driver,action);
        homePage.openPage();
        CookieUtils.addCookie(driver, ConfigPropInfo.TEST_DATA_DIR + "cookies/" + "pingan.cookie");
        homePage.openPage();
        if (!homePage.isLogined()) {
            homePage.login(userName,pass);
            CookieUtils.saveCookie(driver, ConfigPropInfo.TEST_DATA_DIR + "cookies/" + "pingan.cookie",".pingan.com.cn");
            action.waitForPageLoad();
        }
        homePage.login(userName,pass);
        homePage.switchMain();
        homePage.newOffer("21077","2100700666");
        action.waitForPageLoad();
        action.pause(3000l);
    }*/
}
